package org.xxmi.cors.configurations;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * api 的相关信息
     *
     * @return
     */
    private ApiInfo apiInfo() {
        ApiInfoBuilder info = new ApiInfoBuilder();
        info.title("学习 Spring Boot Cors");
        info.description("描述：就是学习");
        info.termsOfServiceUrl("服务条款：");
        Contact contact = new Contact("雨夜", "www.xxmi.cn", "swagger@xxmi.cn");
        info.contact(contact);
        info.version("v1.0");
        return info.build();
    }
}
